<?php

namespace App\Models;


class ShopGoodsOrderModel
{
    /**
     * 查询商品订单
     * entry
     * return array
     * */
    public static function getGoodsOrderList($conn,$ShopGoodsOrderExample,$identical){
        $Sql="SELECT `order_id`, `order_no`,`member_id`,`merchant_id`,`goods_id`,`sku_id`,`order_number`,`order_price`,`order_total_price`,`logistics_name`,`logistics_no`,`receipt_name`,`receipt_phone`,`receipt_address`,`order_state`,`remark`,`create_time` FROM `shop_goods_order` where `is_delete` = 0 and `member_id` = '$ShopGoodsOrderExample->member_id' and `order_state` in($ShopGoodsOrderExample->order_state) order by `create_time` desc limit $identical->pageStart,$identical->limit";
        return $conn->readConn($Sql,true);
    }
    /**
     * 查询商品订单单条
     * entry
     * return array
     * */
    public static function getGoodsOrder($conn,$ShopGoodsOrderExample){
        $Sql="SELECT `order_id`, `order_no`,`member_id`,`merchant_id`,`goods_id`,`sku_id`,`order_number`,`order_price`,`order_total_price`,`logistics_name`,`logistics_no`,`receipt_name`,`receipt_phone`,`receipt_address`,`order_state`,`remark`,`create_time` FROM `shop_goods_order` where `is_delete` = 0 and `member_id` = '$ShopGoodsOrderExample->member_id' and `order_id` =$ShopGoodsOrderExample->order_id";
        return $conn->readConn($Sql);
    }
    public static function getGoodsOrderInfo($conn,$ShopGoodsOrderExample){
        $Sql="SELECT `order_id`,`order_no`,`member_id`,`merchant_id`,`goods_id`,`sku_id`,`is_delete`,`order_state` FROM `shop_goods_order` where `order_id` = '$ShopGoodsOrderExample->order_id' and `member_id` = '$ShopGoodsOrderExample->member_id' and `is_delete` = 0";
        return $conn->readConn($Sql);
    }
    /**
     * 插入订单信息
     * entry conn,$ShopGoodsOrderExample
     * return int
     * */
    public static function insertShopGoodsOrderInside($conn,$ShopGoodsOrderExample){
        $insertSql = "insert into `shop_goods_order`(`order_no`,`member_id`,`merchant_id`,`goods_id`,`sku_id`,`order_number`,`order_price`,`order_total_price`,`receipt_name`,`receipt_phone`,`receipt_address`,`order_state`,`remark`,`type`) values ('$ShopGoodsOrderExample->order_no','$ShopGoodsOrderExample->member_id','$ShopGoodsOrderExample->merchant_id','$ShopGoodsOrderExample->goods_id','$ShopGoodsOrderExample->sku_id','$ShopGoodsOrderExample->order_number','$ShopGoodsOrderExample->order_price','$ShopGoodsOrderExample->order_total_price','$ShopGoodsOrderExample->receipt_name','$ShopGoodsOrderExample->receipt_phone','$ShopGoodsOrderExample->receipt_address',1,'$ShopGoodsOrderExample->remark',$ShopGoodsOrderExample->type)";
        return $conn->executeConn($insertSql);
    }
    /**
     * 修改
     * entry $CtcSettingExample
     * return int
     * */
    public static function upShopGoodsOrderInside($conn,$ShopGoodsOrderExample){
        $joinSql="";
        if($ShopGoodsOrderExample->is_delete !=null){
            $joinSql.=" `is_delete` = '$ShopGoodsOrderExample->is_delete',";
        }
        if($ShopGoodsOrderExample->order_state !=null){
            $joinSql.=" `order_state` = '$ShopGoodsOrderExample->order_state',";
        }
        if($joinSql !=null){
            $innerJoin = rtrim($joinSql,",");
            $upUserSql="UPDATE  `shop_goods_order` SET $innerJoin WHERE `order_id` = '$ShopGoodsOrderExample->order_id'";
            return $conn->executeConn($upUserSql);
        }
    }
}